package com.foton.bigdatastudy.partiton;


import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @Author RenPu
 * @Date 2023/8/21 16:54
 * @Version 1.0
 * @Description: mapper :任务分发层层
 **/
public class WordCountMapper extends Mapper<LongWritable, Text, Text,IntWritable> {

    Text outK=new Text();

    IntWritable outV=new IntWritable(1);

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {

        //整行数据读取
        String line = value.toString();

        String[] words = line.split(" ");

        for (String word : words) {
            outK.set(word);

            //将map输出的值，交由上下文然后交由reduce阶段
            context.write(outK,outV);

        }

    }
}
